//
//  ATDetailFirstSectionTableViewCell.m
//  Adorable_Things
//
//  Created by huzhiyan on 16/1/13.
//  Copyright © 2016年 Banana Inc. All rights reserved.
//

#import "ATDetailFirstSectionTableViewCell.h"

@implementation ATDetailFirstSectionTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _priceButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _priceButton.frame = CGRectMake((kWidth - 120) / 2, 20, 120, 30);
        _priceButton.layer.cornerRadius = 15;
        _priceButton.titleLabel.font = [UIFont systemFontOfSize:15];
        _priceButton.backgroundColor = [UIColor redColor];
        [_priceButton setImage:[UIImage imageNamed:@"iconfont-baisegouwuche"] forState:(UIControlStateNormal)];
        [_priceButton setImageEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 90)];
        [_priceButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 20)];
        [self.contentView addSubview:_priceButton];
        
        _buyerLabel = [[UILabel alloc] init];
        _buyerLabel.textColor = [UIColor grayColor];
        _buyerLabel.font = [UIFont systemFontOfSize:13];
        _buyerLabel.numberOfLines = 0;
        [self.contentView addSubview:_buyerLabel];
        
    }
    return self;
}

- (void)setModel:(ATDetailModel *)model
{
    _model = model;
    NSString *price = [NSString stringWithFormat:@"￥%.2f",[_model.price floatValue]];
    [_priceButton setTitle:price forState:(UIControlStateNormal)];
    if (model.buyer_comment.length != 0) {
        _buyerLabel.text = model.buyer_comment;
        CGFloat height = [ATDetailFirstSectionTableViewCell cellHeightForModel:model];
        _buyerLabel.frame = CGRectMake(20, _priceButton.bottom + 20, kWidth - 40, height);
    }
}

+ (CGFloat)cellHeightForModel:(ATDetailModel *)model
{
    NSDictionary *fontDic = @{NSFontAttributeName : [UIFont systemFontOfSize:13]};
    CGRect textRect = [model.buyer_comment boundingRectWithSize:CGSizeMake(kWidth - 40, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:fontDic context:nil];
    return textRect.size.height;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
